module.exports = function ($scope, $state, $resource, $modal, toaster,$stateParams, aa_type){
    console.log($stateParams.type, aa_type);
    var type = $stateParams.type || aa_type;
    //头条列表
    $scope.search = function (pageNo){
        var para = {
            'pageNo': pageNo || $scope.currentPage,
            'pageSize': $scope.itemsPerPage,
            'type': type
            
        }
        
        $resource('/api/as/mc/headline/findPageList', {}, {}).save(para, function(res){
            if(res.errcode === 0){
                $scope.list = res.data.results;
                $scope.totalItems = res.data.totalRecord;

                $scope.currentPage = pageNo;
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }
  
    init();
    //初始化列表
    function init(){
        $scope.currentPage = 1;		//当前页码
        $scope.itemsPerPage = 10;	//每页显示几条
        $scope.searchform = {};
        $scope.search(1);
    }

    //添加or修改
    $scope.saveLawInfo = function(info) {
        if(info != 1){
            var para = info;
            para.openstate = false;
            para.type = type;
            para.flag = false;

         }else{
            var para = {
                'type': type,
                'openstate': false,
                'flag': true
            }

         }
        var modalInstance = $modal.open({
            template: require('../views/addheadline.html'),
            controller: 'addheadline',
            size: 'lg',
            resolve: {
                item : function () {
                    return para;
                },
                flag : function () {
                    return para == 1;
                }
            }
        });
        //关闭模态框刷新页面
        modalInstance.result.then(function() {
            init();
        });
    }

        //查看
        $scope.gatLawInfo = function(info) {
            info.openstate = true;
            info.hisstate = true;
            info.examinestate = false;
            info.type = type;
            var modalInstance = $modal.open({
                template: require('../views/addheadline.html'),
                controller: 'addheadline',
                size: 'lg',
                resolve: {
                    item : function () {
                        return info;
                    },
                    flag : function () {
                        return info == 1;
                    }
                }
            });
            //关闭模态框刷新页面
            modalInstance.result.then(function() {
                init();
            });
        }

    //删除
    $scope.delete = function (info){
        if (confirm('确认删除此条记录吗？') == true) {
            var para = {
                'id' : info.id
            }
            $resource('/api/as/mc/headline/updateDel', {}, {}).get(para, function(res){
                if(res.errcode === 0){
                    toaster.success({title: '', body: '删除成功'});
                    init();
                }else{
                    toaster.error({title: '', body: res.errmsg});
                }
            });
        }
    }

    //发布
    $scope.updateup = function (info){
        var para = {
            'id' : info.id
        }
        $resource('/api/as/mc/headline/updateStateUP', {}, {}).get(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '提交成功'});
                init();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

    //停止发布
    $scope.updatedown = function (info){
        var para = {
            'id' : info.id
        }
        $resource('/api/as/mc/headline/updateStateDown', {}, {}).get(para, function(res){
            if(res.errcode === 0){
                toaster.success({title: '', body: '撤回成功'});
                init();
            }else{
                toaster.error({title: '', body: res.errmsg});
            }
        });
    }

};